﻿using System;
using System.Collections.Generic;
using System.Text;
using BBMS.DLL.Base;
namespace BBMS.DLL.DataContract
{
    public class LoaiNhaCungCap : ObjectBase
    {
        public string Ma;
        public string Ten;
        public int MucUuTien;
        public bool TheoThoiVu = false;
        public LoaiNhaCungCap()
        {
        }

        public LoaiNhaCungCap(string ma, string ten, int mucUuTien, bool theothoivu)
        {
            this.Ma = ma;
            this.Ten = ten;
            this.MucUuTien = mucUuTien;
            this.TheoThoiVu = theothoivu;
        }

        public override object Key
        {
            get
            {
                return this.Ma;
            }
        }
        public override string Name
        {
            get
            {
                return this.Ten;
            }
        }
        public override string TableName
        {
            get
            {
                return "SupplierType";
            }
        }

        public override string[] KeyFields
        {
            get
            {
                return new string[] { "Ma" };
            }
        }
        public override string[] IDFields
        {
            get
            {
                return new string[] { "Ma" };
            }
        }
        public override System.Data.DataTable GetObjectDataTable()
        {
            System.Data.DataTable dt = new System.Data.DataTable(this.TableName);
            dt.Columns.Add("Ma", typeof(String));
            dt.Columns.Add("Ten", typeof(String));
            dt.Columns.Add("MucUuTien", typeof(int));
            dt.Columns.Add("TheoThoiVu", typeof(bool));
            return dt;
        }
        public override System.Data.DataRow ObjectToDataRow()
        {
            System.Data.DataRow row = this.GetObjectDataTable().NewRow();
            row["Ma"] = this.Ma;
            row["Ten"] = this.Ten;
            row["MucUuTien"] = this.MucUuTien;
            row["TheoThoiVu"] = this.TheoThoiVu;
            return row;
        }

        public override BBMS.DLL.Base.ObjectBase DataRowToObject(System.Data.DataRow row)
        {
            LoaiNhaCungCap obj = null;
            try
            {
                obj = new LoaiNhaCungCap(row["Ma"].ToString(), row["Ten"].ToString(), 
                    CommonTools.Helper.StringToInt(row["MucUuTien"].ToString()),
                    (row["TheoThoiVu"].ToString().Equals("True")));
            }
            catch { }
            return obj;
        }

        public override BBMS.DLL.Base.ObjectBase DataReaderToObject(MySql.Data.MySqlClient.MySqlDataReader rd)
        {
            LoaiNhaCungCap obj = null;
            try
            {
                obj = new LoaiNhaCungCap(rd["Ma"].ToString(), rd["Ten"].ToString(),
                    CommonTools.Helper.StringToInt(rd["MucUuTien"].ToString()),
                    (rd["TheoThoiVu"].ToString().Equals("True")));
            }
            catch { }
            return obj;
        }

        public override string InsertNew()
        {
            string str = base.InsertNew();
            if (str == "") ObjectLists.LoaiNhaCungCapList.Add(this);
            return str;
        }
        public override string Delete()
        {
            string str = base.Delete();
            if (str == "") ObjectLists.LoaiNhaCungCapList.Remove(this);
            return str;
        }
        public override string Save()
        {
            string str = base.Save();
            if (str == "") ObjectLists.LoaiNhaCungCapList.Update(this);
            return str;
        }
    }
}
